package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-07-04
 * Time: 20:42
 */
class MyThread extends  Thread {//创建一个自己的类，并且重写当中的方法
    public void run() {
        while (true) {
            System.out.println("hello 1111111111111111111");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class ThreadDemo1 {
    public static void main(String[] args) {
        Thread thread = new MyThread();//先创建一个MyThread实例
        thread.start();
        //run不会创建新的线程，run是在main线程中执行的

        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
